home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / OTHER_LA / 1410B.ZIP / ST3_SRC.ZIP / TTY.ST < prev    next >
Text File  |  1989-04-01  |  4KB  |  145 lines

  1. *
  2. * Little Smalltalk, version 3
  3. * Written by Tim Budd, Oregon State University, July 1988
  4. *
  5. *  methods for the unix front end - single process version
  6. *
  7. *
  8. Methods Class 'all'
  9.     addMethod    | m |
  10.         m <- Method new; text: ''.
  11.         (self doEdit: m)
  12.             ifTrue: [ methods at: m name put: m ]
  13. |
  14.     doEdit: method
  15.         " edit a method until it compiles correctly "
  16.         [ method text: method text edit.
  17.           (method compileWithClass: self)
  18.             ifTrue: [ ^ true ]
  19.             ifFalse: [ smalltalk inquire: 'edit again (yn) ? ' ]
  20.                 ] whileTrue.
  21.         ^ false
  22. |
  23.     display
  24.         ('Class name: ', name asString)  print.
  25.         (superClass notNil)
  26.             ifTrue: [ ('Superclass: ', superClass ) print ].
  27.         'Instance Variables:' print.
  28.         variables isNil
  29.             ifTrue: [ 'no instance variables ' print ]
  30.             ifFalse: [ variables display ].
  31.         'Subclasses: ' print.
  32.         self subClasses display
  33. |
  34.     editMethod: name    | m |
  35.         m <- self methodNamed: name.
  36.         (m notNil)
  37.             ifTrue: [ self doEdit: m ]
  38.             ifFalse: [ superClass notNil
  39.                     ifTrue: [ superClass editMethod: name ]
  40.                     ifFalse: [ 'no such method' print ] ]
  41. |
  42.     readInstanceVariables
  43.         self variables:
  44.             ((smalltalk getPrompt: 'Instance Variables? ')
  45.             words: [:x | x isAlphabetic ])
  46. |
  47.     readMethods
  48.         [ smalltalk inquire: 'Add a method (yn) ? ' ]
  49.             whileTrue: [ self addMethod ]
  50. |
  51.     viewMethod: methodName    | m |
  52.         m <- self methodNamed: methodName.
  53.         (m notNil) 
  54.             ifTrue: [ m signature print.  m text print ]
  55.             ifFalse: [ 'no such method' print ]
  56. ]
  57. Methods Smalltalk 'all'
  58.     getPrompt: aString
  59.         stdout printNoReturn: aString.
  60.         ^ stdin getString
  61. |
  62.     inquire: aString    | response |
  63.         response <- self getPrompt: aString.
  64.         response isNil
  65.             ifTrue: [ ^ false ].
  66.         ^ 'Yy' includes: (response at: 1 ifAbsent: [])
  67. |
  68.     echo
  69.         " enable - disable echo input "
  70.         echoInput <- echoInput not
  71. ]
  72. Methods String 'all'
  73.     edit    | file text |
  74.         file <- File new; 
  75.             scratchFile;
  76.             open: 'w';
  77.             print: self;
  78.             close.
  79.         (editor, ' ', file name) unixCommand.
  80.         file open: 'r'.
  81.         text <- file asString.
  82.         file close; delete.
  83.         ^ text
  84. |
  85.     print
  86.         stdout print: self
  87. ]
  88. *
  89. * initialization code
  90. * this is executed once, by the initial image maker
  91. *
  92. *
  93. Methods Smalltalk 'doit'
  94.     error: aString
  95.         " print a message, and remove current process "
  96.         stderr print: aString.
  97.         scheduler currentProcess; trace; terminate.
  98. ]
  99. Methods Scheduler 'get commands'
  100.     initialize    | string |
  101.         <2>.
  102.         string <- smalltalk getPrompt: '>    '.
  103.         string isNil
  104.             ifTrue: [ notdone <- false ]
  105.             ifFalse: [ (string size > 0)
  106.                 ifTrue: [ 
  107.                     echoInput ifTrue:
  108.                         [ string print ].
  109.                     [ string value print ] fork ] ]
  110. ]
  111. Methods UndefinedObject 'initial image'
  112.     createGlobals    | aBlock |
  113.         " create global variables in initial image "
  114.         true <- True new.
  115.         false <- False new.
  116.         smalltalk <- Smalltalk new.
  117.         files <- Array new: 15.
  118.         stdin <- File new; name: 'stdin'; mode: 'r'; open.
  119.         stdout <- File new; name: 'stdout'; mode: 'w'; open.
  120.         stderr <- File new; name: 'stderr'; mode: 'w'; open.
  121.         editor <- 'vi'.
  122.         " create a dictionary of classes "
  123.         classes <- Dictionary new.
  124.         symbols binaryDo: [:x :y | 
  125.             (y class == Class)
  126.                 ifTrue: [ classes at: x put: y ] ].
  127.         scheduler <- Scheduler new.
  128.         " create the initial system process "
  129.         " note the delayed recursive call "
  130.         aBlock <- [ files do: [:f | f notNil ifTrue: [ f open ]].
  131.                    systemProcess <- aBlock newProcess.
  132.                    echoInput <- false.
  133.                    scheduler run ].
  134.         systemProcess <- aBlock newProcess.
  135. |
  136.     initialize
  137.         " initialize the initial object image "
  138.         self createGlobals.
  139.         File new;
  140.             name: 'systemImage';
  141.             open: 'wb';
  142.             saveImage;
  143.             close.
  144. ]
  145.